<!--*******************************************************-->
<!--**** ADVANCED SEARCH TEMPLATE FOR NBRIGHTSTORE      ***-->
<!--*******************************************************-->
<!-- In this template we are using a function defined in nbbajax.js "nbxcheckifnull", so include the script here -->
<script type="text/javascript" src="/DesktopModules/NBright/NBrightBuy/Themes/config/js/nbbajax.js"></script>

<!-- These postback fields are create to keep data that is used to do the section criteria -->
<!-- They are used the the "search" tokens, js is used to change these values to what the client selects, the values here are set to the default.-->
[<tag id='nbb-min' type='postback' value="0" />] <!-- Used in is in stock range check -->
[<tag id='nbb-max' type='postback' value="9999999" />] <!-- Used in is in stock range check -->
[<tag id='nbb-off' type='postback' value="-1" />] <!-- Used in is in stock range check -->

<!-- This "disabledsearchtokens" token is used to turn off search tokens, if off then no SQL will be created for the token -->
<!-- It is a semi-colon seperated list of the search token ids, if the id appears in the list then no SQL is created for that token -->
<!-- This is used if you want the user to deselect search options. -->
[<tag id='disabledsearchtokens' type='postback' value="" />]

<!-- Add postback field for filtermode -->
[<tag id='navigationmode' type='postback' value="" />]

<script>

$(document).ready(function() {

	//Update filter mode
	[<tag type='if' settings='rblfiltermode' testvalue='f' display='{ON}' />]
	$("input[[id*='navigationmode']]").val('f');
	[<tag type='endif' />]
	
    //Update the is in stock flag, by altering the criteria input fields.
    $("input[[id*='chkInStock']]").change(function() {
		if ($("input[[id*='chkInStock']]").prop('checked') == true) $("input[[id*='nbb-min']]").val('1');
		if ($("input[[id*='chkInStock']]").prop('checked') == false) $("input[[id*='nbb-min']]").val('0');
    });
	
	if ('[Settings:chktextsearch]'=='False')
	{
		// ALL Text search is turned off in the settings, so use JS to update the "disabledsearchtokens" for all text search tokens -->
		var disabledlist = $("input[[id*='disabledsearchtokens']]").val();
		if (disabledlist.indexOf('search0;') == -1) disabledlist = disabledlist + 'search0;';
		if (disabledlist.indexOf('search1;') == -1) disabledlist = disabledlist + 'search1;';
		if (disabledlist.indexOf('search2;') == -1) disabledlist = disabledlist + 'search2;';
		if (disabledlist.indexOf('search3;') == -1) disabledlist = disabledlist + 'search3;';
		if (disabledlist.indexOf('search4;') == -1) disabledlist = disabledlist + 'search4;';
		if (disabledlist.indexOf('search5;') == -1) disabledlist = disabledlist + 'search5;';
		if (disabledlist.indexOf('search6;') == -1) disabledlist = disabledlist + 'search6;';
		if (disabledlist.indexOf('search7;') == -1) disabledlist = disabledlist + 'search7;';
		if (disabledlist.indexOf('search8;') == -1) disabledlist = disabledlist + 'search8;';
		// Update disabled fields to the postback field -->
		$("input[[id*='disabledsearchtokens']]").val(disabledlist);
	}


	// if we do any postback then check if we want to disable any search criteria
	$("body").on("click", ".postbacklink", function () {
		$('.processing').show();
		nbxcheckifnull('.advsearchtext','search0;search1;search2;search3;search4;search5;search6;search7;search8;'); // disble text search if empty
		nbxcheckifselected('input[[id*="chknbbcats"]]','search40');
		nbxcheckifselected('input[[id*="chkcatsgrp1"]]','search50');
		nbxcheckifselected('input[[id*="chkcatsgrp2"]]','search60');
	});
		
  // Range slider
  $(function() {
    // Price
    $( "#pricerangeslider" ).slider({
      range: true,
      step: 100,
      min: 0,
      max: 5000,
      values: [[ 0, 5000 ]],
      slide: function( event, ui ) {
        $( "input[[id*='txtFrom']]" ).val( ui.values[[ 0 ]]);
        $( "input[[id*='txtTo']]" ).val( ui.values[[ 1 ]]);
      }
    });
    $( "input[[id*='txtFrom']]" ).val( $( "#pricerangeslider" ).slider( "values", 0 ));
    $( "input[[id*='txtTo']]" ).val( $( "#pricerangeslider" ).slider( "values", 1 ));
  });


});

</script>

<!-- Token to create the SQL required for the textbox search -->
[<tag id="search0" type="meta" action="open" sqloperator="and" />]
[<tag id="search1" type="meta" action="like" search="genxml/textbox/txtsearch" static="%" sqlcol="NB3.ProductName" />]
[<tag id="search2" active="{Settings:chktxtsummary}" type="meta" action="like" search="genxml/textbox/txtsearch" sqlcol="NB3.Summary"  sqloperator="or" />]
[<tag id="search3" active="{Settings:chktxtmanufacturer}" type="meta" action="like" search="genxml/textbox/txtsearch" sqlcol="NB3.Manufacturer" sqloperator="or" />]
[<tag id="search4" active="{Settings:chktxtseoname}" type="meta" action="like" search="genxml/textbox/txtsearch" sqlcol="NB3.SEOName" sqloperator="or" />]
[<tag id="search5" active="{Settings:chktxttagwords}" type="meta" action="like" search="genxml/textbox/txtsearch" sqlcol="NB3.TagWords" sqloperator="or" />]
[<tag id="search6" active="{Settings:chktxtseopagetitle}" type="meta" action="like" search="genxml/textbox/txtsearch" sqlcol="NB3.SEOPageTitle" sqloperator="or" />]
[<tag id="search7" active="{Settings:chkdescription}" type="meta" action="like" search="genxml/textbox/txtsearch" sqlfield="genxml/lang/genxml/edt/description" sqloperator="or" />]
[<tag id="search8" type="meta" action="close" />]

<!-- Token to create the SQL required for the price range selection -->
[<tag id="search20" active="{Settings:chkpricerange}" type="meta" action="open" sqloperator="and" />]
[<tag id="search21" active="{Settings:chkpricerange}" type="meta" action="range" searchfrom="genxml/textbox/txtfrom" searchto="genxml/textbox/txtto" sqlcol="NB3.FromPrice" />]
[<tag id="search22" active="{Settings:chkpricerange}" type="meta" action="close" />]

<!-- Token to create the SQL required for the is in stock only selection -->
[<tag id="search31" active="{Settings:chkinstock}" type="meta" action="open" sqloperator="and" />]
[<tag id="search32" active="{Settings:chkinstock}" type="meta" action="range" searchfrom="genxml/hidden/nbb-min" searchto="genxml/hidden/nbb-max" sqlcol="NB3.Qty" />]
[<tag id="search33" active="{Settings:chkinstock}" type="meta" action="equal" search="genxml/hidden/nbb-off" sqlcol="NB3.Qty" sqloperator="or" />]
[<tag id="search34" active="{Settings:chkinstock}" type="meta" action="close" />]

<!-- Token to create the SQL required for the is in category selection -->
[<tag id="search40" active="{Settings:chkcatselect}" type="meta" action="cats" search="genxml/checkboxlist/chknbbcats" sqloperator="and" selectoperator="{Settings:rblcatsearchtype}" />]

<!-- Token to create the SQL required for the is in AND group1 category selection -->
[<tag id="search50" active="{Settings:chkgroupselect1}" type="meta" action="cats" search="genxml/checkboxlist/chkcatsgrp1" sqloperator="and" selectoperator="{Settings:rblcatsearchtype}" />]

<!-- Token to create the SQL required for the is in AND group1 category selection -->
[<tag id="search60" active="{Settings:chkgroupselect2}" type="meta" action="cats" search="genxml/checkboxlist/chkcatsgrp2" sqloperator="and" selectoperator="{Settings:rblcatsearchtype}" />]

[<tag id="search101" type="meta" action="cat" />]

<!-- Define all the poosible orderby columns we want, this will specfied by the dropdownlist values-->
[<tag id="orderby0" type="hidden" value="NB3.FromPrice" />]
[<tag id="orderby1" type="hidden" value="NB3.FromPrice DESC" />]
[<tag id="orderby2" type="hidden" value="NB3.ProductName" />]
[<tag id="orderby3" type="hidden" value="NB3.Manufacturer" />]
[<tag id="orderby4" type="hidden" value="NB3.ProductRef" />]
[<tag id="orderby5" type="hidden" value="NB3.Qty" />]

<!--*********************************-->
<!--***  START OF DISPLAY SECTION ***-->
<!--*********************************-->
<!-- This section display the control needs to do an advanced search, certain fields can be hidden by the module settings. -->

<div class="nbs dnnForm">

<ul class="advancedsearch">

<!-- text search -->
[<tag type='if' settings='chktextsearch' testvalue='True' display='{ON}' />]
<li class="searchtext">[<tag id='txtSearch' cssclass='advsearchtext' type='textbox' maxlength='150' />]<span class="filterlabel">[<tag type="valueof" resourcekey="ProductSearch.SearchText" />]</span>
</li>
[<tag type='endif' />]

<!-- sorting -->
[<tag type='if' settings='orderselector' testvalue='True' display='{ON}' />]
<li class="orderby">
[<tag id="ddlOrderBy" type="dropdownlist" resourcekey="ProductSearch.ddlOrderBy" datavalue="0;1;2;3;4;5" />]<span class="filterlabel">[<tag type="valueof" resourcekey="General.OrderBy" />]</span>
</li>
[<tag type='endif' />]

<!-- Price range search -->
[<tag type='if' settings='chkpricerange' testvalue='True' display='{ON}' />]
<li class="pricerange">
[<tag id="txtFrom" cssclass="rangemin" type="textbox" />]<span class="rangeseperator">[<tag type="valueof" resourcekey="ProductSearch.PriceRangeSeperator" />]</span>[<tag id="txtTo" cssclass="rangemax" type="textbox" />]
<div id="pricerangeslider"></div>
<span class="filterlabel">[<tag type="valueof" resourcekey="ProductSearch.PriceRange" />]</span>
</li>
[<tag type='endif' />]

[<tag type="if" function="productcount" modulekey="ProductView" testvalue="0" display="{OFF}" />]<!-- Hide Manufacturers and Attributes category search when current category has zero items -->
<li><h5>[<tag type="valueof" resourcekey="ProductSearch.RefineSearch" />]</h5></li>

<!-- Is in Stock search -->
[<tag type='if' settings='chkinstock' testvalue='True' display='{ON}' />]
<li class="stock">[<tag id="chkInStock" type="checkbox" Text="" />][<tag type="valueof" resourcekey="ProductSearch.OnlyInStock" />]</li>
[<tag type='endif' />]

<!-- category search -->
[<tag type='if' settings='chkcatselect' testvalue='True' display='{ON}' />]
<li class="manufacturer"><h6>{Settings:parentcatref}</h6>
[<tag id="chknbbcats" type="catcheckboxlist" displaylevels="{Settings:displaylevels}" parentref="{Settings:parentcatref}" showarchived="False" showhidden="False" catreflist="{Settings:catreflist}" RepeatDirection="0" RepeatColumns="{Settings:catrepeatcolumns}" filtermode="true" modulekey="{Settings:targetmodulekey}" />]</li>
[<tag type='endif' />]

<!-- START: AND category search on Group 1 -->
[<tag type='if' settings='chkgroupselect1' testvalue='True' display='{ON}' />]
<li class="attributes"><h6>{Settings:parentcatref1}</h6>
[<tag id="chkcatsgrp1" type="catcheckboxlist" displaylevels="{Settings:displaylevels1}" parentref="{Settings:parentcatref1}" showarchived="False" showhidden="False" catreflist="{Settings:catreflist1}" RepeatDirection="0" RepeatColumns="{Settings:catrepeatcolumns1}" filtermode="true" modulekey="{Settings:targetmodulekey}" />]</li>
[<tag type='endif' />]
<!-- END: AND category search on Group 1 -->

<!-- START: AND category search on Group 1 -->
[<tag type='if' settings='chkgroupselect2' testvalue='True' display='{ON}' />]
<li class="promotions"><h6>{Settings:parentcatref2}</h6>
[<tag id="chkcatsgrp2" type="catcheckboxlist" displaylevels="{Settings:displaylevels2}" parentref="{Settings:parentcatref2}" showarchived="False" showhidden="False" catreflist="{Settings:catreflist2}" RepeatDirection="0" RepeatColumns="{Settings:catrepeatcolumns2}" filtermode="true" modulekey="{Settings:targetmodulekey}" />]</li>
[<tag type='endif' />
<!-- END: AND category search on Group 1 -->
[<tag type="endif"  />]<!-- End Manufacturers and Attributes category search when current category has zero items -->

<li class="buttons">
[<tag id="cmdAdvSearch" type="linkbutton" cssclass="postbacklink searchpostbacklink {Settings:primarybuttonclass}" resourcekey="ProductSearch.Search" commandname="search" commandargument="ItemID" />]
[<tag id="cmdAdvReset" type="linkbutton" cssclass="postbacklink {Settings:secondarybuttonclass}"  resourcekey="ProductSearch.Reset" commandname="resetsearch" commandargument="ItemID" />]
<span class="processing" style="display:none;">[<tag type="label" resourcekey="ProductSearch.Processing" />]</span>
</li>

</ul>
</div>
